//set main namespace
goog.provide('helloworld');


//get requirements
goog.require('lime.Director');
goog.require('lime.Scene');
goog.require('lime.Layer');

goog.require('ee.block');
goog.require('ee.arrow');
//goog.require('lime.transition.Transition');
//goog.require('lime.transition.Dissolve');
//goog.require('lime.transition.SlideInRight');

var queue = ["A1","A2","A3","A4","A5","A6","A7","A8","A9",
             "B1","B2","B3","B4","B5","B6","B7","B8","B9",
             "C1","C2"];

var blocks= new Array();

var leftArrow ;
var rightArrow;
var topArrow ;
var bottomArrow ;
// entrypoint
helloworld.start = function(){
    this.WIDTH  = 800;
    this.HEIGHT = 480;
	var director    = new lime.Director(document.body,this.WIDTH,this.HEIGHT);
	var scene       = new lime.Scene();
    var layer       = new lime.Layer();

    for(i=0;i<20;i++){
        var r=Math.floor(Math.random()*19);
        var tmp = queue[r];
        queue[r] = queue[19-r];
        queue[19-r] = tmp;
    }

    for(var i=0;i<5;i++){
        for(var j=0;j<4;j++){
            var rect = new ee.Block(i,j,queue[j*5+i]);
            blocks.push(rect);
            layer.appendChild(rect);
        }
    }

    scene.appendChild(layer);

    leftArrow = new ee.Arrow("left").setHidden(true);
    rightArrow = new ee.Arrow("right").setHidden(true);
    topArrow = new ee.Arrow("top").setHidden(true);
    bottomArrow = new ee.Arrow("bottom").setHidden(true);

    scene.appendChild(leftArrow);
    scene.appendChild(rightArrow);
    scene.appendChild(topArrow);
    scene.appendChild(bottomArrow);

	director.replaceScene(scene);

}

helloworld.obtainBlockBy_ij = function(i,j){
    for(var block in blocks){
        if(blocks[block].posi == i && blocks[block].posj ==j){
            return blocks[block];
        }
    }
    return null;
};

helloworld.removeArrow = function(){
    leftArrow.hideArrow();
    rightArrow.hideArrow();
    topArrow.hideArrow();
    bottomArrow.hideArrow();
};

//this is required for outside access after code is compiled in ADVANCED_COMPILATIONS mode
goog.exportSymbol('helloworld.start', helloworld.start);
